package org.example.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.example.entity.Test;
import org.example.mapper.TestMapper;
import org.example.service.TestService;
import org.example.util.JobUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * @author yangzhenyu
 * @version 1.0
 * @description:
 * @date 2023/4/26 10:41
 */
@Slf4j
@Service
public class TestServiceImpl extends ServiceImpl<TestMapper, Test>  implements TestService {

    @Autowired
    TestMapper mapper;


    @Override
    public Long queryMaxId() {
        return mapper.queryMaxId();
    }
    @Transactional
    @Override
    public Boolean addAll(int num) {
        List<Test> list = Lists.newArrayList();
        for (int index = 0;index <num ; index++){
            Test test = Test.builder()
                    .age(JobUtil.nextInt(10,110))
                    .name(JobUtil.simpleUUID())
                    .build();
            list.add(test);

        }
        return this.saveBatch(list);
    }

    @Override
    public List<Test> query(Long beginId, int shardingItem, int shardingTotalCount, int limitPage) {
        return mapper.query(beginId,shardingItem,shardingTotalCount,limitPage);
    }
}
